package com.xyzpool.test;

import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat;

/**
 * 测试有关正则表达式用来去除一些字符串中的一些特定字符.
 * @author yangzhen
 *
 */
public class RegExpFilterTestor {
	public static void main(String[] args) {
		String[] strs = {"$ Export file to local purchase^","$2013-11-13 08:27:09 Export file to local purchase^","$ORDER IMPORT FROM AMAZON^"};
		for (int i = 0; i < strs.length; i++) {
			String str = strs[i];
			System.out.print("orignal:"+str+",");
			System.out.println("after:"+replaceStr(str));
		}
	}
	
	public static String replaceStr(String str){
		if(str==null||str.trim()=="")
			return str;
		int index = str.indexOf("Export file to local purchase");
		//1 Date + Export file to local purchase
		if(index>=20){
			String pattern = "yyyy-MM-dd HH:mm:ss";
			String tmp = str.substring(index-20,index).trim();
			DateTime date = DateTimeFormat.forPattern(pattern).parseDateTime(tmp);
			if(date!=null){
				str = str.replace(date.toString(pattern)+" Export file to local purchase","");
			}else{
				str = str.replace("Export file to local purchase","");
			}
		}else if(index>-1){
			str = str.replace("Export file to local purchase","");
		}
		str = str.replace("ORDER IMPORT FROM AMAZON","");//2
		return str.trim();
	}
}
